package team.sun.sss.controller.student;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import team.sun.sss.dao.staff.StaffDao;
import team.sun.sss.dao.student.FamilyDao1;
import team.sun.sss.dao.student.StudentDao;
import team.sun.sss.pojo.staff.Staff;
import team.sun.sss.pojo.student.Student1;
import team.sun.sss.pojo.user.User;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class StudentUpdateController {
    @Autowired
    StudentDao studentDao;
    @Autowired
    FamilyDao1 familyDao1;
    @Autowired
    StaffDao staffDao;
    //学生修改个人信息
    @GetMapping("/student_update")
    public String studentInfoUpdate(HttpSession session, Model model,
                                    String stuAddress, String stuPostalCode, String stuQq,String stuWechat, String stuPhone,
                                    String stuEmail, String stuAdvantage, String stuPastIll,String stuMarriage,
                                    String stuBankId,String stuBankName,String stuBankAddress
    ) {
        User user = (User) session.getAttribute("loginInfo");
        studentDao.studentUpdate(user.getUserId(), stuAddress, stuPostalCode, stuQq,
                stuWechat, stuPhone, stuEmail, stuAdvantage, stuPastIll,stuMarriage,stuBankId,stuBankName,stuBankAddress);
        model.addAttribute("studentinfo1", studentDao.selectStuById(user.getUserId()));
        model.addAttribute("familyinfo1", familyDao1.getFamilyList(user.getUserId()));
        return "student/student_info";
    }
    //学工修改所有学生的信息
    @RequestMapping("/staff_update_stu")
    public String staffUpdateStu(Model model, @ModelAttribute(value = "studentInfo") Student1 student1
            , String stuImg, int stuId, String stuName, String stuPastName, String stuSex,
                                 String stuBirth, String stuIdCard, String stuProvince, String stuCountry, String stuNation, String stuMarriage, String stuDormitory,
                                 String stuAddress, String stuPostalCode, String stuPoliticalOutlook,
                                 String stuQq, String stuWechat, String stuPhone, String stuEmail, String stuAdvantage,
                                 String stuPastIll, String stuBankId, String province, String city, String stuGrade, String stuClass,
                                 String stuStates, String stuLength, String stuEnterTime, String stuLevel, String stuSource, String stuExamNum,
                                 String stuInstructor, String stuIsPoor, String stuType,int stuIdPast,String stuEnterType,
                                 String stuPinyin,String stuBankName,String stuBankAddress,String stuAssistanceLevel, String stuSpecialAttention) {
        //如果修改后的学号跟别人的学号重复，修改失败
        /*List<Student1> student11=studentDao.stuIdList(stuIdPast);
        if(student11!=null) {
            if (stuId == student11.getStuId()) {
                model.addAttribute("stuIdError", "学号重复");
            } else {

            }
        }*/
        studentDao.staffUpdateStu(stuImg, stuId, stuName, stuPastName, stuSex,
                stuBirth, stuIdCard, stuProvince, stuCountry, stuNation,
                stuMarriage, stuDormitory,
                stuAddress, stuPostalCode, stuPoliticalOutlook,
                stuQq, stuWechat, stuPhone, stuEmail, stuAdvantage,
                stuPastIll, stuBankId, province, city, stuGrade, stuClass,
                stuStates, stuLength, stuEnterTime, stuLevel, stuSource, stuExamNum,
                stuInstructor, stuIsPoor, stuType, stuEnterType,
                stuPinyin, stuBankName, stuBankAddress, stuAssistanceLevel, stuSpecialAttention,
                stuIdPast);
      //  model.addAttribute("stuIdError", "success");
        model.addAttribute("AllStudentList", studentDao.studentList());
        return "student/staff_stu_manage";
    }
    //辅导员只修改学生的特别关注
    @RequestMapping("/instructor_stu_update")
    public String instructorUpdateStu(Model model, HttpSession session,
                                      Integer stuId, String stuSpecialAttention) {
        User user = (User) session.getAttribute("loginInfo");
        studentDao.updateStudentAttention(stuId, stuSpecialAttention);

        Staff staff = staffDao.getStaffByName(user.getUserId());
        model.addAttribute("instructorStuInfo", studentDao.selectStuByInstructor(staff.getStaName()));
        model.addAttribute("major", studentDao.selectStuByMajor(staff.getStaName()));
        return "student/instructor_manage_stu";
    }
}
